﻿/// <reference path="Interpolaters.js" />
/*
    Name:           Random Noise
    Description:
                    This library provides the implementation
                    of various different interpolation techniques
    Date: 2014/02/07
    Version: 0.0.1
    Author: Dave Russell 
*/
RandomNoise = new function () {

    this.RandomArray = new Array();
    this.Size = 512;

    this.Init = function (dimensions, size, array) {
        array = new Array(size);
        if (dimensions == 1) {
            for (var i = 0; i < size; i++) {
                array[i] = Math.random();
            }
            return array;
        } else {
            array = new Array(size);
            for (var i = 0; i < size; i++) {
                var nd = dimensions - 1;
                array[i] = this.Init(nd, size, array[i]);
            }
            return array;
        }
    };

    this.Get1D = function (x) {
        if (this.RandomArray.length == 0) {
            this.RandomArray = this.Init(1, this.Size, this.RandomArray);
        }

        var xmin = Math.floor(x) % this.Size;
        
        return this.RandomArray[xmin];
    };

    this.Get2D = function (x, y) {
        if (this.RandomArray.length == 0) {
            this.RandomArray = this.Init(2, this.Size, this.RandomArray);
        }

        var xmin = Math.floor(x) % this.Size;
        var ymin = Math.floor(y) % this.Size;
       
        return this.RandomArray[xmin][ymin];
    };

    this.Reinit = function () {
        this.RandomArray = new Array();
    }

};